<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">
    <button @click="showChildrenData">在父组件里的按钮</button>
    <cpn ref="aaa"></cpn>
    <cpn ref="bbb"></cpn>

</div>
<template id="cpn">
    <div>
        <h2>我是子组件的模板</h2>
    </div>
</template>
<script src="../js/vue.js"></script>
<script>
    const aaa = new Vue({
        el: "#app",
        data: {
            message: "hello,guys",
        },
        methods: {
            showChildrenData(){
                console.log(this.$children[0].cdata);
                this.$children[0].showMessage();

                console.log(this.$refs.aaa.cdata);
                this.$refs.aaa.showMessage();
            }

        },
        components: {
            'cpn': {
                template: "#cpn",
                data() {
                    return {
                        cdata: "我是子组件里的一个data"
                    }
                },
                methods: {
                    showMessage(){
                        console.log("我是子组件里的一个函数");
                    }
                }
            }
        }
    })
</script>
</body>
</html>